//
//  BSZNavigationBar.m
//  BuSuanZi
//
//  Created by HZ on 2025/2/15.
//

#import "BSZNavigationBar.h"

@implementation BSZNavigationBar

- (void)setRightMenuButtonArray:(NSArray *)rightMenuButtonArray{
    _rightMenuButtonArray = rightMenuButtonArray;
    
    for (NSInteger i=0; i<_rightMenuButtonArray.count; i++) {
        BSZButton *button = [[BSZButton alloc]initWithFrame:CGRectMake(self.width-_rightMenuButtonArray.count*NAV_BAR_HEIGHT+i*NAV_BAR_HEIGHT, STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT, NAV_BAR_HEIGHT)];
        button.index = 600+i;
        [button setImage:[UIImage imageNamed:_rightMenuButtonArray[i]] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(rightElementAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button];
    }
}
- (void)rightElementAction:(BSZButton *)sender{
    if (self.returnNavbarRightBlock) {
        self.returnNavbarRightBlock(sender.index);
    }
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    [self addSubview:self.statusBar];
    [self addSubview:self.navigationBar];
    
    [self.navigationBar addSubview:self.leftMenuButton];
    [self.navigationBar addSubview:self.rightMenuButton];
    [self.navigationBar addSubview:self.titleLabel];
    [self.navigationBar addSubview:self.bottomLineView];
}


#pragma mark ---懒加载
- (UIView *)statusBar{
    if (!_statusBar) {
        _statusBar = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, STATUS_BAR_HEIGHT)];
        _statusBar.backgroundColor = WhiteColor;
    }
    return _statusBar;
}

- (UIView *)navigationBar{
    if (!_navigationBar) {
        _navigationBar = [[UIView alloc]initWithFrame:CGRectMake(0, STATUS_BAR_HEIGHT, SCREEN_WIDTH, NAV_BAR_HEIGHT)];
        _navigationBar.backgroundColor = WhiteColor;
    }
    return _navigationBar;
}

- (UIView *)bottomLineView{
    if (!_bottomLineView) {
        _bottomLineView = [[UIView alloc]initWithFrame:CGRectMake(0, NAV_BAR_HEIGHT-1, SCREEN_WIDTH, 1)];
        _bottomLineView.backgroundColor = ColdLightGrayColor;
//        _bottomLineView.hidden = YES;
    }
    return _bottomLineView;
}

- (BSZButton *)leftMenuButton{
    if (!_leftMenuButton) {
        _leftMenuButton = [[BSZButton alloc]initWithFrame:CGRectMake(10, 0, NAV_BAR_HEIGHT, NAV_BAR_HEIGHT)];
        _leftMenuButton.hidden = YES;
    }
    return _leftMenuButton;
}

- (BSZButton *)rightMenuButton{
    if (!_rightMenuButton) {
        _rightMenuButton = [[BSZButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-NAV_BAR_HEIGHT-10, 0, NAV_BAR_HEIGHT, NAV_BAR_HEIGHT)];
        _rightMenuButton.hidden = YES;
    }
    return _rightMenuButton;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(NAV_BAR_HEIGHT+20, 0, SCREEN_WIDTH-2*NAV_BAR_HEIGHT-40, NAV_BAR_HEIGHT)];
        _titleLabel.backgroundColor = ClearColor;
        _titleLabel.font = BoldSystemFont(16);
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.textColor = BlackColor;
        _titleLabel.hidden = NO;
    }
    return _titleLabel;
}


@end
